<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建财务档案库</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>档案信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">档案编号</label>
                        <div class="layui-input-block">
                            <input type="text" id="number" readonly placeholder="系统自动生成编号" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>档案分类</label>
                        <div class="layui-input-block">
                            <div id="dangfen"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enginid" class="layui-input enginid" onclick="openPage('../public/choose_engin.php?dom=enginid&page=coss','80%','80%')">
                            <div class="choose_div" id="enginid" key="0"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_engin.php?dom=enginid&page=coss','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>档案名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>档案日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="dangdt" id="dangdt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">相关方</label>
                        <div class="layui-input-block">
                            <input type="text" name="xianger" id="xianger" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">涉及金额</label>
                        <div class="layui-input-block">
                            <input type="text" name="shefee" id="shefee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>档案类型</label>
                        <div class="layui-input-block">
                            <select id="danglei" name="danglei" lay-filter="danglei">
                                <option value="原件">原件</option>
                                <option value="复印件">复印件</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">页码数</label>
                        <div class="layui-input-block">
                            <input type="text" name="yeshu" id="yeshu" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">入库份数</label>
                        <div class="layui-input-block">
                            <input type="number" name="runum" id="runum" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>归档份数</label>
                        <div class="layui-input-block">
                            <input type="number" name="guinum" id="guinum" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>归档日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="guidt" id="guidt" placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">归档人</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=guier&type=user&single=1', '770px', '490px');"></div>
                                <div class="tanxiannei" id="guier"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=guier&type=user&single=1', '770px', '490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="guier_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_enginid = getQueryVariable('enginid') || 0;
    var param_dangtype = getQueryVariable('dangtype') || 0;
    var param_jiaoid = getQueryVariable('jiaoid') || 0;

    $("#commentForm").validate({
        rules: {
            name: {required: true},
            guinum: {required: true},
            guidt: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            guinum: {required: "请输入"},
            guidt: {required: "请选择"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_coss_add, data:{jiaoid:param_jiaoid,enginid:param_enginid,dangtype:param_dangtype}}).done(function(res){
            if (res.code === 2000) {
                var jiaoinfo = res.data.jiaoinfo;
                if(jiaoinfo){
                    $("#name").val(jiaoinfo.name);
                    $("#dangdt").val(jiaoinfo.dangdt);
                    $("#xianger").val(jiaoinfo.xianger);
                    $("#shefee").val(jiaoinfo.shefee);
                    $("#danglei").val(jiaoinfo.danglei);
                    $("#yeshu").val(jiaoinfo.yeshu);
                    $("#runum").val(jiaoinfo.yinum);
                    $("#guinum").val(jiaoinfo.yinum);
                    $("#explain").val(jiaoinfo.explain);

                    var engininfo = jiaoinfo.engininfo;
                    if(engininfo){
                        set_choose_btn('enginid',engininfo.id,engininfo.name);
                    }
                }else{
                    var engininfo = res.data.engininfo;
                    if(engininfo){
                        set_choose_btn('enginid',engininfo.id,engininfo.name);
                    }
                }






                xmselect_dan('dangfen', res.data.dangfen, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#dangfen").find('xm-select').removeClass('error');
                    }else{
                        $("#dangfen").find('xm-select').addClass('error');
                    }
                });

                if(res.data.guier_info.length > 0){
                    tan_tags_init('#guier', res.data.guier_info);
                }

                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });

        form.on('submit(add)', function(data){
            data.field.enginid = get_choose_val('enginid');
            data.field.guier = tan_tags_getvalue("#guier", 'user');
            var validRes = $("#commentForm").valid();

            if(!data.field.dangfen){
                $("#dangfen").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#dangfen").find('xm-select').removeClass('error');
            }

            if(!validRes){return false;}


            data = parseMoney(data);
            data.field.jiaoid = param_jiaoid;
            data.field.dangtype = param_dangtype;
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_coss_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
